<template>
  <div>
    <vxe_table
      :options="options"
      @handleTableBtn="handleTableBtn"
      ref="baseTable"
    >
      <template #btn> </template>
    </vxe_table>
    <RefuseDialog ref="RefuseDialog" @success="success"></RefuseDialog>
    <HistoryDialog ref="HistoryDialog"></HistoryDialog>
    <Info ref="Info"></Info>
  </div>
</template>

<script>
import vxe_table from "@/components/table/vxe_table.vue";
import tableMixin from "@/mixins";
import { hasBtnAuth, parseTime } from "@/utils";
import { getMerchantList, approval } from "@/api/review";
import RefuseDialog from "./comps/refuseDialog.vue";
import HistoryDialog from "./comps/historyDialog.vue";
import Info from "./comps/info.vue";
export default {
  mixins: [tableMixin],
  components: {
    vxe_table,
    RefuseDialog,
    HistoryDialog,
    Info
  },
  data() {
    return {
      options: {
        id: "usertable",
        apiFn: getMerchantList,
        columns: [
          {
            field: "name",
            title: "企业名称",
            search: true,
            valueType: "input",
          },
          {
            field: "simpleName",
            title: "企业简称",
          },
          {
            field: "contactName",
            title: "联系人",
          },
          { field: "mobile", title: "联系电话" },
          { field: "orgCode", title: "商家码" },
          {
            field: "state",
            title: "状态",
            type: "html",

            formatter: ({ row }) => {
              if (row.state == 0) {
                return "<span style='color:#e6a23c'>申请</span>";
              } else if (row.state == 1) {
                return "<span style='color:green'>同意</span>";
              } else {
                return "<span style='color:red'>拒绝</span>";
              }
            },
          },
          {
            field: "createTime",
            title: "时间",
            type: "html",
            formatter: ({ row }) => parseTime(row.createTime),
          },
        ],
        btnWidth: 300,
        btn: [
          {
            title: "通过",
            type: "success",
            handleName: "handleAccept",
            show: (row) => row.state == 0,
          },
          {
            title: "不通过",
            handleName: "handleInject",
            type: "danger",
            show: (row) => row.state == 0,
          },
          {
            title: "审核记录",
            handleName: "handleHistory",
            show: (row) => row.state != 0,
          },
          {
            title: "详情",
            handleName:'handleInfo'
          },
        ],
      },
    };
  },

  methods: {
    edit(row, index) {
      console.log(row, index);
    },
    handleADD() {
      this.$refs.addDialog.open();
    },
     handleAccept(row) {
      this.$confirm("确定通过", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const res = await approval({
            orgCode: row.orgCode,
            result: 1,
            note:'通过'
          });
          if (res.status == 0) {
            this.$message({
              type: "success",
              message: "success",
            });
            this.success();
          }
        })
        .catch(() => {});
    },
    handleInject(row){
      this.$refs.RefuseDialog.open(row)
    },
    handleHistory(row){
      this.$refs.HistoryDialog.open(row)
    },
    handleInfo(row){
      this.$refs.Info.open(row)
    }
  },
};
</script>
